<template>
	<div>
    <!-- 订单经理审核 -->
		<div class="top_border">
			<TopFilter
		      :list="topFilterList"
		      :cols="3"
          labelWidth="100"
          @filterChange="filterChangeHandle"
		    ></TopFilter>
		</div>

		<FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    />

    <Drawer
    :visible.sync="visible"
    title="订单经理审核"
    :width="1050"
    destroyOnClose
    :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
		>
		  <!--<子组件 @close="closeHandle"/>-->
		  <BuyingModal :type="handleType" :rowData="formData" @close="closeHandler" />
		</Drawer>

    <BaseDialog
	    :visible.sync="visibleToExamines"
	    title="审核"
	    destroyOnClose
	    @close="closeDialogs"
	    :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
	  >
	    <toExamines :financialOrManager="financialOrManager" :rowData="formData" @close="closeHandler" @clos2="closeHandle2"></toExamines>
	  </BaseDialog>

	</div>
</template>

<script>
import toExamines from './toExamines'
import { dictionary } from '@/utils/dictMixin';
import BuyingModal from './buyingModal';

import { auditQueries } from '@/api/retail/salesmanage/managerverify';
export default {
	name: 'managerverify',
	mixins: [dictionary],
	components: {
      BuyingModal,
      toExamines
	},
	data() {
		return {
			topFilterList: this.createTopFilters(),
      fetchParams: {},
      visible: false,
      visibleToExamines:false,
      fetchApi: auditQueries,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      financialOrManager:null,

		}
	},
  created (){
    this.fetchParams.soStatus = 14041002
  },
	methods: {
		createTopFilters() {
	      return [
          {
	          type: 'INPUT',
	          label: '客户名称',
	          fieldName: 'customerName',
	          placeholder: '请输入...'
          },
          {
	          type: 'INPUT',
	          label: '手机号码',
	          fieldName: 'mobilePhone',
	          placeholder: '请输入...'
	        },
	        {
	          type: 'RANGE_DATE',
	          label: '开单日期',
	          fieldName: 'sheetCreateDateStart|sheetCreateDateEnd',
	          placeholder: '请选择日期...'
	        },
	        {
	          type: 'INPUT',
	          label: '订单编号',
	          fieldName: 'soNo',
	          placeholder: '请输入...'
          },
          {
	          type: 'SELECT',
            label: '业务类型',
            fieldName: 'businessType',
            placeholder: '请选择...',
            initialValue: "",
            itemList: [{ text: '一般销售', value: 14031001 },{ text: '客户退车', value: 14031002 }],
	        }


	      ];
	  },
    createTableColumns() {
      return [
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 120,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" disabled={ props.row.soStatus == 14041002? false : true } type="text" onClick={() => this.editHandle(props.row)}>审核</el-button>
              </div>
            );
          }
        },
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '订单编号',
          dataIndex: 'soNo',
          sorter: true,
          filter: true,
          width: 180,
          filterType: 'input',
        },
        {
          title: '业务类型',
          dataIndex: 'businessType',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [{ text: '一般销售', value: 14031001 },{ text: '客户退车', value: 14031002 }],
          editable: true,
          editType: 'select',
          editItems: [{ text: '一般销售', value: 14031001 },{ text: '客户退车', value: 14031002 }]
          
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '手机号码',
          dataIndex: 'mobilePhone',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '开单日期',
          dataIndex: 'sheetCreateDate',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props =>{
            return <span>{ this.formatDates(props.row.sheetCreateDate) } </span>
          }
        },
        {
          title: '审核结果',
          dataIndex: 'auditingResult',
          // sorter: true,
          // filter: true,
          // filterType: 'input',
          // filterItems: this.createDictList('1416'),
          render: props => {
            return <span>待审核</span>;
            // return <span>{props.row.auditingResult ? this.createDictText(props.row.auditingResult, '1416') : '待审核'}</span>;
          }
        },
        {
          title: '审核时间',
          dataIndex: 'auditedByManagerDate',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props =>{
            return <span>{ this.formatDates(props.row.auditedByManagerDate) } </span>
          }
        },
      ];
    },
    filterChangeHandle (val){ //搜索
      this.fetchParams = Object.assign({}, val)
      this.fetchParams.soStatus = 14041002;
    },
    formatDates (value) { //时间过滤
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == "") {
        return "";
      }
      var date = new Date(Number(value));
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      return year + "-" + month + "-" + day;
    },
    addHandle() {
      this.handleType = 'add';
      this.showHandler();
    },
    editHandle(row) { //打开审核界面
    console.log(row,"row")
    if(row.businessType == 14031002){
      this.visibleToExamines=true
      this.financialOrManager = 3
      this.handleType = 'show';
      this.formData = row;
    }else{
      this.visible = true;
      this.handleType = 'show';
      this.formData = row;
      this.financialOrManager =1
    }
      
      // this.showHandler();
    },
    showHandler() {
      this.dialogTitle = `订单经理审核${this.conf[this.handleType]}`;
      this.visible = true;
    },
    closeHandler(val) {
      this.visible = val;
      console.log(456)
      this.visibleToExamines=false
      this.fetchParams = { ...this.fetchParams };
    },
    closeHandle2 (val){ //整体返回
      this.visibleToExamines=false
      this.fetchParams = { ...this.fetchParams };
    },


	},
	mounted() {
	   this.BaseTable = this.$refs.table.$refs.pageTable;
	}
}</script>

<style scoped="scoped" lang="less">

.top_border{
	border: 1px solid @borderColor;
	padding-top: 15px;
	margin-bottom: 15px;
}
</style>
